home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / libgimp / gimpmath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-02-13  |  2.8 KB  |  116 lines

  1. /* LIBGIMP - The GIMP Library 
  2.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
  3.  *
  4.  * gimpmath.h
  5.  *
  6.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball                
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Lesser General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Lesser General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Lesser General Public
  19.  * License along with this library; if not, write to the
  20.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21.  * Boston, MA 02111-1307, USA.
  22.  */
  23.  
  24. #ifndef __GIMPMATH_H__
  25. #define __GIMPMATH_H__
  26.  
  27. #include <math.h>
  28.  
  29. #ifdef HAVE_IEEEFP_H
  30. #include <ieeefp.h>
  31. #endif
  32.  
  33. #ifdef G_OS_WIN32
  34. #include <float.h>
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif /* __cplusplus */
  40.  
  41.  
  42. /* Some portability enhancing stuff. For use both by the gimp app
  43.  * as well as plug-ins and modules.
  44.  *
  45.  * Include this instead of just <math.h>.
  46.  */
  47.  
  48. #ifndef G_PI            /* G_PI will be in GLib eventually */
  49. #define G_PI    3.14159265358979323846
  50. #endif
  51. #ifndef G_PI_2            /* As will G_PI_2 */
  52. #define G_PI_2  1.57079632679489661923
  53. #endif
  54. #ifndef G_PI_4            /* As will G_PI_4 */
  55. #define G_PI_4  0.78539816339744830962
  56. #endif
  57. #ifndef G_SQRT2            /* As will G_SQRT2 */
  58. #define G_SQRT2 1.4142135623730951
  59. #endif
  60.  
  61.  
  62. #ifdef G_OS_WIN32
  63. #define G_MAXRAND G_MAXINT
  64. #define GIMP_WIN32_RAND_FUNC() g_random_int_range (0, G_MAXRAND)
  65. #define GIMP_WIN32_SRAND_FUNC(seed) g_random_set_seed (seed)
  66. #else
  67. #ifndef RAND_MAX
  68. #define G_MAXRAND G_MAXINT
  69. #else
  70. #define G_MAXRAND RAND_MAX
  71. #endif
  72. #endif
  73.  
  74. #ifdef HAVE_RINT
  75. #define RINT(x) rint(x)
  76. #else
  77. #define RINT(x) floor ((x) + 0.5)
  78. #endif
  79.  
  80. #define ROUND(x) ((int) ((x) + 0.5))
  81.  
  82. /* Square */
  83. #define SQR(x) ((x) * (x))
  84.  
  85. /* limit a (0->511) int to 255 */
  86. #define MAX255(a)  ((a) | (((a) & 256) - (((a) & 256) >> 8)))
  87.  
  88. /* clamp a >>int32<<-range int between 0 and 255 inclusive */
  89. /* broken! -> #define CLAMP0255(a)  ((a & 0xFFFFFF00)? (~(a>>31)) : a) */
  90. #define CLAMP0255(a)  CLAMP(a,0,255)
  91.  
  92. #define gimp_deg_to_rad(angle) ((angle) * (2.0 * G_PI) / 360.0)
  93. #define gimp_rad_to_deg(angle) ((angle) * 360.0 / (2.0 * G_PI))
  94.  
  95. #ifdef HAVE_FINITE
  96. #define FINITE(x) finite(x)
  97. #else
  98. #ifdef HAVE_ISFINITE
  99. #define FINITE(x) isfinite(x)
  100. #else
  101. #ifdef G_OS_WIN32
  102. #define FINITE(x) _finite(x)
  103. #else
  104. #ifdef __EMX__
  105. #define FINITE(x) isfinite(x)
  106. #endif /* __EMX__ */
  107. #endif /* G_OS_WIN32 */
  108. #endif /* HAVE_ISFINITE */
  109. #endif /* HAVE_FINITE */
  110.  
  111. #ifdef __cplusplus
  112. }
  113. #endif /* __cplusplus */
  114.  
  115. #endif /* __GIMPMATH_H__ */
  116.